<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-aifc.html" />
<link rel="prev" href="module-audioop.html" />
<link rel="parent" href="mmedia.html" />
<link rel="next" href="module-aifc.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>19.2 imageop -- Manipulate raw image data</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="19.1 audioop  "
  href="module-audioop.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="19. multimedia Services"
  href="mmedia.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="19.3 aifc  "
  href="module-aifc.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-audioop.html">19.1 audioop  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="mmedia.html">19. Multimedia Services</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-aifc.html">19.3 aifc  </a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION0021200000000000000000">
19.2 <tt class="module">imageop</tt> --
         Manipulate raw image data</a>
</h1>

<p>
<a name="module-imageop"></a>

<p>
The <tt class="module">imageop</tt> module contains some useful operations on images.
It operates on images consisting of 8 or 32 bit pixels stored in
Python strings.  This is the same format as used by
<tt class="function">gl.lrectwrite()</tt> and the <tt class="module"><a href="module-imgfile.html">imgfile</a></tt> module.

<p>
The module defines the following variables and functions:

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-4517' xml:id='l2h-4517' class="exception">error</tt></b></dt>
<dd>
This exception is raised on all errors, such as unknown number of bits
per pixel, etc.
</dd></dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4518' xml:id='l2h-4518' class="function">crop</tt></b>(</nobr></td>
  <td><var>image, psize, width, height, x0, y0, x1, y1</var>)</td></tr></table></dt>
<dd>
Return the selected part of <var>image</var>, which should be
<var>width</var> by <var>height</var> in size and consist of pixels of
<var>psize</var> bytes. <var>x0</var>, <var>y0</var>, <var>x1</var> and <var>y1</var> are like
the <tt class="function">gl.lrectread()</tt> parameters, i.e. the boundary is
included in the new image.  The new boundaries need not be inside the
picture.  Pixels that fall outside the old image will have their value
set to zero.  If <var>x0</var> is bigger than <var>x1</var> the new image is
mirrored.  The same holds for the y coordinates.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4519' xml:id='l2h-4519' class="function">scale</tt></b>(</nobr></td>
  <td><var>image, psize, width, height, newwidth, newheight</var>)</td></tr></table></dt>
<dd>
Return <var>image</var> scaled to size <var>newwidth</var> by <var>newheight</var>.
No interpolation is done, scaling is done by simple-minded pixel
duplication or removal.  Therefore, computer-generated images or
dithered images will not look nice after scaling.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4520' xml:id='l2h-4520' class="function">tovideo</tt></b>(</nobr></td>
  <td><var>image, psize, width, height</var>)</td></tr></table></dt>
<dd>
Run a vertical low-pass filter over an image.  It does so by computing
each destination pixel as the average of two vertically-aligned source
pixels.  The main use of this routine is to forestall excessive
flicker if the image is displayed on a video device that uses
interlacing, hence the name.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4521' xml:id='l2h-4521' class="function">grey2mono</tt></b>(</nobr></td>
  <td><var>image, width, height, threshold</var>)</td></tr></table></dt>
<dd>
Convert a 8-bit deep greyscale image to a 1-bit deep image by
thresholding all the pixels.  The resulting image is tightly packed and
is probably only useful as an argument to <tt class="function">mono2grey()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4522' xml:id='l2h-4522' class="function">dither2mono</tt></b>(</nobr></td>
  <td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert an 8-bit greyscale image to a 1-bit monochrome image using a
(simple-minded) dithering algorithm.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4523' xml:id='l2h-4523' class="function">mono2grey</tt></b>(</nobr></td>
  <td><var>image, width, height, p0, p1</var>)</td></tr></table></dt>
<dd>
Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
All pixels that are zero-valued on input get value <var>p0</var> on output
and all one-value input pixels get value <var>p1</var> on output.  To
convert a monochrome black-and-white image to greyscale pass the
values <code>0</code> and <code>255</code> respectively.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4524' xml:id='l2h-4524' class="function">grey2grey4</tt></b>(</nobr></td>
  <td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert an 8-bit greyscale image to a 4-bit greyscale image without
dithering.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4525' xml:id='l2h-4525' class="function">grey2grey2</tt></b>(</nobr></td>
  <td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert an 8-bit greyscale image to a 2-bit greyscale image without
dithering.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4526' xml:id='l2h-4526' class="function">dither2grey2</tt></b>(</nobr></td>
  <td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert an 8-bit greyscale image to a 2-bit greyscale image with
dithering.  As for <tt class="function">dither2mono()</tt>, the dithering algorithm
is currently very simple.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4527' xml:id='l2h-4527' class="function">grey42grey</tt></b>(</nobr></td>
  <td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert a 4-bit greyscale image to an 8-bit greyscale image.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4528' xml:id='l2h-4528' class="function">grey22grey</tt></b>(</nobr></td>
  <td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert a 2-bit greyscale image to an 8-bit greyscale image.
</dl>

<p>
<dl><dt><b><tt id='l2h-4529' xml:id='l2h-4529'>backward_compatible</tt></b></dt>
<dd>
If set to 0, the functions in this module use a non-backward
compatible way of representing multi-byte pixels on little-endian
systems.  The SGI for which this module was originally written is a
big-endian system, so setting this variable will have no effect.
However, the code wasn't originally intended to run on anything else,
so it made assumptions about byte order which are not universal.
Setting this variable to 0 will cause the byte order to be reversed on
little-endian systems, so that it then is the same as on big-endian
systems.
</dd></dl>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="19.1 audioop  "
  href="module-audioop.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="19. multimedia Services"
  href="mmedia.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="19.3 aifc  "
  href="module-aifc.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-audioop.html">19.1 audioop  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="mmedia.html">19. Multimedia Services</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-aifc.html">19.3 aifc  </a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
